import time

from selenium import webdriver
from selenium.webdriver.common.by import By

from unittest import TestCase


class TestLogin(TestCase):

    # 登陆成功用例
    def testLogin1(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "123456"
        expect = "个人理财系统"

        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "//input[@id='password' and @name='password']").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(2)

        # 获取实际结果
        result = driver.find_element(By.XPATH,"//div[@id='logo']/a").text  # text取出文本数据


        self.assertEqual(expect,result)


        time.sleep(2)

        driver.quit()

    def testLogin2(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "admin"
        password = "123456"
        expect = "后台管理系统"

        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "//input[@id='password' and @name='password']").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(2)

        # 获取实际结果
        result = driver.find_element(By.XPATH,"//div[@id='logo']/a").text  # text取出文本数据


        self.assertEqual(expect,result)


        time.sleep(2)

        driver.quit()

    def testLogin3(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi3"
        password = "123456"
        expect = "个人理财系统"

        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "//input[@id='password' and @name='password']").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(2)

        # 获取实际结果
        result = driver.find_element(By.XPATH,"//div[@id='logo']/a").text  # text取出文本数据


        self.assertEqual(expect,result)


        time.sleep(2)

        driver.quit()

    def testLogin4(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "lisi"
        password = "1234567"
        expect = "个人理财系统"

        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "//input[@id='password' and @name='password']").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(2)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.quit()

    def testLogin5(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "admin1"
        password = "123456"
        expect = "后台管理系统"

        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "//input[@id='password' and @name='password']").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(2)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.quit()

    def testLogin6(self):
        driver = webdriver.Chrome()

        driver.get("http://localhost:90/")

        driver.maximize_window()

        # 定位
        '''
            8大定位：
                xpath:绝对路径，相对定位
                id,css,class_name,tag....
        '''
        username = "admin"
        password = "1234567"
        expect = "后台管理系统"

        # driver.find_element(By.ID,"username").send_keys("lisi")

        driver.find_element(By.XPATH, "//input[@id='username' and @name='username']").send_keys(username)

        time.sleep(2)
        # 输入密码
        # driver.find_element(By.ID,"password").send_keys("123456")
        driver.find_element(By.XPATH, "//input[@id='password' and @name='password']").send_keys(password)

        time.sleep(2)
        # 点击登陆
        # driver.find_element(By.ID,"login_btn").click()
        driver.find_element(By.XPATH, "//button[@id='login_btn']").click()

        time.sleep(2)

        # 获取实际结果
        result = driver.find_element(By.XPATH, "//div[@id='logo']/a").text  # text取出文本数据

        self.assertEqual(expect, result)

        time.sleep(2)

        driver.quit()













